package com.tjc.spring.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {

    private static final String DEFAULT_CONFIG = "application.properties";

    private Properties properties;

    public PropertiesUtil(String config) {
        this.properties = new Properties();
        InputStream in = null;
        if (config == null || "".equals(config)) {
            config = DEFAULT_CONFIG;
        }
        in = this.getClass().getClassLoader().getResourceAsStream(config);
        try {
            this.properties.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public PropertiesUtil() {
        this(null);
    }

    public String getByKey(String key) {
        return this.properties.get(key).toString();
    }
}
